package com.unisal.java;

import java.util.Observable;
import java.util.Observer;

public class ForecastDisplayWithObservable implements Observer, MostraElementos {
	private Double currentPressure = 29.92;  
	private Double lastPressure;

	public ForecastDisplayWithObservable(Observable observable) {
		observable.addObserver(this);
	}

	public void update(Observable observable, Object arg) {
		if (observable instanceof WeatherDataWithObservable) {
			WeatherDataWithObservable weatherData = (WeatherDataWithObservable)observable;
			lastPressure = currentPressure;
			currentPressure = weatherData.getPressao();
			mostra();
		}
	}

	@Override
	public void mostra() {
		System.out.print("Forecast: ");
		if (currentPressure > lastPressure) {
			System.out.println("Improving weather on the way!");
		} else if (currentPressure == lastPressure) {
			System.out.println("More of the same");
		} else if (currentPressure < lastPressure) {
			System.out.println("Watch out for cooler, rainy weather");
		}
		
	}
}
